﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;

using BusinnessLogic;
using Model;
using DataLayer;


namespace scrumbench
{
    public partial class AddToTeamForm : Form
    {
        public AddToTeamForm()
        {
            InitializeComponent();

        }
        private int userid;

        public int Userid
        {
            get { return userid; }
            set { userid = value; }
        }
        private int teamid;

        public int Teamid
        {
            get { return teamid; }
            set { teamid = value; }
        }

        private void AddToTeamForm_Load(object sender, EventArgs e)
        {
            ManageUsers mijnusers = new ManageUsers();
            List<User> allmembers = new List<User>();
            allmembers = mijnusers.PopulateUserlistZonderTeams();

            foreach (User mijnuser in allmembers)
            {
                checkedListBox1.Items.Add(mijnuser);
                //checkedListBox1.Tag = mijnuser.UserID;
            }

            PopulateTeamTreeView mijntreeview = new PopulateTeamTreeView();
            List<Team> allteams = new List<Team>();
            allteams = mijntreeview.PopulateTeamlist();

            foreach (Team mijnteam in allteams)
            {
                comboBox1.Items.Add(mijnteam);
                //comboBox1.Tag = mijnteam.teamID;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex != -1 && checkedListBox1.CheckedItems.Count != 0)
            {

                int teller = checkedListBox1.CheckedItems.Count;

                for (int i = 0; i < teller; i++)
                {


                    User mijnuser = (User)checkedListBox1.CheckedItems[i];


                    Team mijnteam = (Team)comboBox1.SelectedItem;

                    MessageBox.Show("UserID : "+ mijnuser.UserID + " added aan teamID : " + mijnteam.teamID);

                    dlInsertMember tempinsMem = new dlInsertMember();



                     // MessageBox.Show("U heeft " + itemChecked.ToString() +
                    //       " toegevoegd tot team : " + comboBox1.SelectedItem.ToString() + ".");
                    // checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(itemChecked)).ToString() + ".");

                    userid = mijnuser.UserID;
                    teamid = mijnteam.teamID;

                    tempinsMem.InsertmemberToTeam(userid, teamid);

                    this.Close();

                }


               // MessageBox.Show("Congratulations, you have added " + teamnaam);
            }
            else
            {
                if (comboBox1.SelectedIndex == -1)
                {
                    MessageBox.Show("U heeft geen team geselecteerd");
                }
                if (checkedListBox1.CheckedItems.Count == 0)
                {
                    MessageBox.Show("U heeft geen members geselecteerd");
                }
            }

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
